#include <iostream>
#include <string>
#include "contacts.pb.h"

using namespace std;

int main()
{
    string people_str;
    // 序列化
    {
        contacts::PeopleInfo people;
        people.set_name("yss");
        people.set_age(21);
        if(!people.SerializeToString(&people_str))
        {
            cout << "序列化失败" << endl;
            return -1;
        }
        cout << "序列化成功， 结果：" << people_str << endl;
    }
    // 反序列化
    {
        contacts::PeopleInfo people;
        if(!people.ParseFromString(people_str))
        {
            cout << "反序列化失败" << endl;
            return -1;
        }
        cout << "反序列化成功, 结果: " << endl;
        cout << people.name() << endl;
        cout << people.age() << endl;
    }
    return 0;
}